home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src_ansi / ace / c / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-05  |  6.1 KB  |  354 lines

  1. /*
  2.    ** ACE Message Ports.
  3.    ** Copyright (C) 1998 David Benn
  4.    ** 
  5.    ** This program is free software; you can redistribute it and/or
  6.    ** modify it under the terms of the GNU General Public License
  7.    ** as published by the Free Software Foundation; either version 2
  8.    ** of the License, or (at your option) any later version.
  9.    **
  10.    ** This program is distributed in the hope that it will be useful,
  11.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    ** GNU General Public License for more details.
  14.    **
  15.    ** You should have received a copy of the GNU General Public License
  16.    ** along with this program; if not, write to the Free Software
  17.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.    **
  19.    ** Author: David J Benn
  20.    **   Date: 15th February 1994,
  21.    **      22nd August 1994,
  22.    **      1st September 1994
  23.  */
  24.  
  25. #include "acedef.h"
  26. #include <string.h>
  27.  
  28. /* locals */
  29. static char *frame_ptr[] = {"(a4)", "(a5)"};
  30.  
  31. /* externals */
  32. extern int sym;
  33. extern int typ;
  34. extern int obj;
  35. extern int lev;
  36. extern char id[MAXIDSIZE];
  37. extern SYM *curr_item;
  38.  
  39. /* functions */
  40. void message_open (void)
  41. {
  42. /* 
  43.    ** MESSAGE OPEN [#]channel,port-name,mode
  44.  */
  45.   int mtype;
  46.  
  47.   insymbol ();
  48.  
  49.   if (sym == hash)
  50.     insymbol ();
  51.  
  52.   mtype = expr ();
  53.  
  54.   if (mtype == stringtype)
  55.     _error (4);
  56.   else
  57.     {
  58.       /* channel */
  59.       if (make_integer (mtype) == shorttype)
  60.     make_long ();
  61.  
  62.       if (sym != comma)
  63.     _error (16);
  64.       else
  65.     {
  66.       /* port-name */
  67.       insymbol ();
  68.       if (expr () != stringtype)
  69.         _error (4);
  70.       else
  71.         {
  72.           if (sym != comma)
  73.         _error (16);
  74.           else
  75.         {
  76.           /* mode (r,R,w,W) */
  77.           insymbol ();
  78.           if (expr () != stringtype)
  79.             _error (4);
  80.           else
  81.             {
  82.               /* call function */
  83.               gen ("jsr", "_MessageOpen", "  ");
  84.               gen ("add.l", "#12", "sp");
  85.               enter_XREF ("_MessageOpen");
  86.             }
  87.         }
  88.         }
  89.     }
  90.  
  91.     }
  92. }
  93.  
  94. void message_read (void)
  95. {
  96. /* 
  97.    ** MESSAGE READ [#]channel,message-string
  98.  */
  99.   int mtype;
  100.   SYM *storage;
  101.   char addrbuf[40];
  102.  
  103.   insymbol ();
  104.  
  105.   if (sym == hash)
  106.     insymbol ();
  107.  
  108.   mtype = expr ();
  109.  
  110.   if (mtype == stringtype)
  111.     _error (4);
  112.   else
  113.     {
  114.       /* channel */
  115.       if (make_integer (mtype) == shorttype)
  116.     make_long ();
  117.  
  118.       if (sym != comma)
  119.     _error (16);
  120.       else
  121.     {
  122.       /*
  123.          ** Message string. 
  124.        */
  125.       insymbol ();
  126.       if (sym == ident && obj == variable)
  127.         {
  128.           /* 
  129.              ** If string variable/array doesn't exist, 
  130.              ** create a simple variable.
  131.            */
  132.           if (!exist (id, variable) && !exist (id, array))
  133.         {
  134.           /* 
  135.              ** Allocate a simple string variable.
  136.            */
  137.           enter (id, typ, obj, 0);
  138.           enter_DATA("_nullstring:", "dc.b 0");
  139.           gen ("pea", "_nullstring", "  ");
  140.           assign_to_string_variable (curr_item,
  141.                          MAXSTRLEN);
  142.         }
  143.  
  144.           storage = curr_item;
  145.  
  146.           /* 
  147.              ** Is it a string variable or array? 
  148.            */
  149.           if (storage->type != stringtype)
  150.         _error (4);
  151.           else
  152.         {
  153.           /* 
  154.              ** Get address of string pointed to 
  155.              ** by variable/array element.
  156.            */
  157.           itoa (-1 * storage->address, addrbuf, 10);
  158.           strcat (addrbuf, frame_ptr[lev]);
  159.  
  160.           /*
  161.              ** Pass string address to function 
  162.              ** (on stack).
  163.            */
  164.           if (storage->object == array)
  165.             {
  166.               point_to_array (storage, addrbuf);
  167.               gen ("move.l", addrbuf, "d0");
  168.               gen ("add.l", "d7", "d0");
  169.               gen ("move.l", "d0", "-(sp)");
  170.             }
  171.           else
  172.             gen ("move.l", addrbuf, "-(sp)");
  173.  
  174.           insymbol ();
  175.  
  176.           /* call function */
  177.           gen ("jsr", "_MessageRead", "  ");
  178.           gen ("addq", "#8", "sp");
  179.           enter_XREF ("_MessageRead");
  180.         }
  181.         }
  182.       else
  183.         _error (19);    /* variable or array expected */
  184.     }
  185.  
  186.     }
  187. }
  188.  
  189. void message_write (void)
  190. {
  191. /* 
  192.    ** MESSAGE WRITE [#]channel,message-string
  193.  */
  194.   int mtype;
  195.  
  196.   insymbol ();
  197.  
  198.   if (sym == hash)
  199.     insymbol ();
  200.  
  201.   mtype = expr ();
  202.  
  203.   if (mtype == stringtype)
  204.     _error (4);
  205.   else
  206.     {
  207.       /* channel */
  208.       if (make_integer (mtype) == shorttype)
  209.     make_long ();
  210.  
  211.       if (sym != comma)
  212.     _error (16);
  213.       else
  214.     {
  215.       /* message-string */
  216.       insymbol ();
  217.       if (expr () != stringtype)
  218.         _error (4);
  219.       else
  220.         {
  221.           /* call function */
  222.           gen ("jsr", "_MessageWrite", "  ");
  223.           gen ("addq", "#8", "sp");
  224.           enter_XREF ("_MessageWrite");
  225.         }
  226.     }
  227.  
  228.     }
  229. }
  230.  
  231. void message_wait (void)
  232. {
  233. /* 
  234.    ** MESSAGE WAIT [#]channel
  235.  */
  236.   int mtype;
  237.  
  238.   insymbol ();
  239.  
  240.   if (sym == hash)
  241.     insymbol ();
  242.  
  243.   mtype = expr ();
  244.  
  245.   if (mtype == stringtype)
  246.     _error (4);
  247.   else
  248.     {
  249.       /* channel */
  250.       if (make_integer (mtype) == shorttype)
  251.     make_long ();
  252.  
  253.       /* call function */
  254.       gen ("jsr", "_MessageWait", "  ");
  255.       gen ("addq", "#4", "sp");
  256.       enter_XREF ("_MessageWait");
  257.     }
  258. }
  259.  
  260. void message_clear (void)
  261. {
  262. /* 
  263.    ** MESSAGE CLEAR [#]channel
  264.  */
  265.   int mtype;
  266.  
  267.   insymbol ();
  268.  
  269.   if (sym == hash)
  270.     insymbol ();
  271.  
  272.   mtype = expr ();
  273.  
  274.   if (mtype == stringtype)
  275.     _error (4);
  276.   else
  277.     {
  278.       /* channel */
  279.       if (make_integer (mtype) == shorttype)
  280.     make_long ();
  281.  
  282.       /* call function */
  283.       gen ("jsr", "_MessageClear", "  ");
  284.       gen ("addq", "#4", "sp");
  285.       enter_XREF ("_MessageClear");
  286.     }
  287. }
  288.  
  289. void message_close (void)
  290. {
  291. /* 
  292.    ** MESSAGE CLOSE [#]channel
  293.  */
  294.   int mtype;
  295.  
  296.   insymbol ();
  297.  
  298.   if (sym == hash)
  299.     insymbol ();
  300.  
  301.   mtype = expr ();
  302.  
  303.   if (mtype == stringtype)
  304.     _error (4);
  305.   else
  306.     {
  307.       /* channel */
  308.       if (make_integer (mtype) == shorttype)
  309.     make_long ();
  310.  
  311.       /* call function */
  312.       gen ("jsr", "_MessageClose", "  ");
  313.       gen ("addq", "#4", "sp");
  314.       enter_XREF ("_MessageClose");
  315.     }
  316. }
  317.  
  318. void message (void)
  319. {
  320. /* 
  321.    ** MESSAGE OPEN|CLOSE|READ|WRITE|WAIT|CLEAR
  322.  */
  323.  
  324.   insymbol ();
  325.  
  326.   switch (sym)
  327.     {
  328.     case opensym:
  329.       message_open ();
  330.       break;
  331.     case closesym:
  332.       message_close ();
  333.       break;
  334.  
  335.     case readsym:
  336.       message_read ();
  337.       break;
  338.     case writesym:
  339.       message_write ();
  340.       break;
  341.  
  342.     case waitsym:
  343.       message_wait ();
  344.       break;
  345.     case clearsym:
  346.       message_clear ();
  347.       break;
  348.  
  349.     default:
  350.       _error (77);
  351.       break;
  352.     }
  353. }
  354.